#include "reservation_admin.h"

reservation_admin *reservation_admin::instance=NULL;

reservation_admin::reservation_admin(void)
{
	reservation_counter=0;
}

reservation_admin * reservation_admin::get_reservation_admin()
	{
		if (instance==NULL) instance = new reservation_admin();
		return instance;
	};

void reservation_admin::reserve(string movie , int phone)
{
	reservations.push_back(reservation(movie , phone));
	reservation_counter=+1;
}

bool reservation_admin::is_reserved(string movie)
{
	for (int i=0;reservations.size();i++)
	{
		if(reservations[i].get_movie() == movie)
		{ return true ;}
	}
	return false;
}

bool reservation_admin::is_reserved(int phone)
{
 for (int i=0; i<reservations.size(); i++)
 {
  if(reservations[i].get_phone() == phone)
  return true;
 }
 return false;
}

void reservation_admin::cancel_r(int phone)
{
	for (int i=0 ; reservations.size();i++)
	{
		if(reservations[i].get_phone() == phone)
		{
			reservations.erase(reservations.begin() + i);
			break;
		}
	}
}


reservation_admin::~reservation_admin(void)
{
}


string reservation_admin::get_movie(int phone)
{
	for(int i=0;i<reservation_counter;i++)
	{
		if (reservations[i].get_phone()== phone )
		{
			return reservations[i].get_movie();
		}
	};
	return "reservation is not found !";
};